<template>
  <div class="home">
    <Inputs @tableDatas="tableDatas" @vLoadings="vLoadings" :vLoading="vLoading" />
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      v-loading="vLoading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
    >
      <el-table-column fixed type="index" label="序号" width="70"></el-table-column>
      <el-table-column prop="sname" label="课程名称" width="120"></el-table-column>
      <el-table-column prop="tname" label="题型" width="120"></el-table-column>
      <el-table-column prop="title" label="题干" width="147"></el-table-column>
      <el-table-column prop="nname" label="难度" width="70"></el-table-column>
      <el-table-column prop="zhishidian" label="知识点" width="587"></el-table-column>
      <el-table-column label="操作" fixed="right" width="90">
        <template slot-scope="scope">
          <Update :msg="scope.row" style="float: left" />
          <el-popconfirm
            title="这是一段内容确定删除吗？"
            @confirm="del(scope.row)"
          >
            <el-button
              type="text"
              size="small"
              slot="reference"
              style="float: left; margin-left: 9px"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!-- 抽屉 -->
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage1"
        :page-sizes="list.page" 
        :page-size="list.page"
        :pager-count="list.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="list.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import Update from "./components/update.vue";
import Inputs from "./components/input.vue";
import home from "../api/home";

export default {
  name: "Home",
  components: { Inputs, Update },
  data() {
    return {
      //加载框
      vLoading: false,
      drawer: false,
      tableData: [],
      form: {
        name: ""
      },
      // 分页
      list:{
        total:14,
        pageTotal:2,
        page:1,
        pageSize:10,
      }
    };
  },
  methods: {
    handleClick(row) {
      console.log(row);
    },
    //删除
    del(row) {
      home.del(row.qid).then(() => {
        this.getQid(row.qid);
        this.$message({
          message: "恭喜你，删除成功！！！！！！！！！！！！！！！！",
          type: "success"
        });
      });
    },
    //按qid查询数据
    getQid(qid) {
      this.vLoading = true;
      this.axios.get(`/question/qdetails/findAll/${qid}`).then(res => {
        this.vLoading = false;
        this.tableData = res.data;
      });
    },
    tableDatas(data) {
      this.tableData = data;
    },
    vLoadings(data) {
      this.vLoading = data;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
};
</script>
<style scoped>
.home {
  width: 80%;
  margin: auto;color: rgb(105,210,243);
}
.block {
  margin: auto;
  width: 1000px;
  margin-top: 20px;
}
</style>